package com.cadre.system.service.impl;

import com.cadre.system.domain.officer.Chart;
import com.cadre.system.domain.officer.SysConfigEntity;
import com.cadre.system.mapper.ChartMapper;
import com.cadre.system.mapper.IndexCountMapper;
import com.cadre.system.service.IndexCountService;
import com.cadre.system.service.SysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service

public class IndexCountServiceImpl implements IndexCountService {
    @Autowired
    IndexCountMapper indexm;
    @Autowired
    ChartMapper chartMapper;
    @Autowired
    private SysConfigService sysConfigService;

    @Override // com.tdqy.cadre.modular.profess.service.IndexCountService
    public List<Chart> totalCadre() {
        List<Chart> list = this.indexm.totalCadre();
        List<Chart> listNew = new ArrayList<>();
        Long count = this.indexm.getCount();
        Long sum = 0L;
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getName().indexOf("比照") != -1) {
                sum = Long.valueOf(sum.longValue() + list.get(i).getValue().longValue());
            } else {
                listNew.add(list.get(i));
            }
        }
        Chart c2 = new Chart();
        c2.setName("企业干部");
        c2.setValue(sum);
        listNew.add(c2);
        Chart c = new Chart();
        c.setName("省管干部总数");
        c.setValue(count);
        listNew.add(c);
        return listNew;
    }

    @Override // com.tdqy.cadre.modular.profess.service.IndexCountService
    public List<Chart> totalEducation() {
        return this.indexm.totalEducation();
    }

    @Override // com.tdqy.cadre.modular.profess.service.IndexCountService
    public List<Chart> totalInstitution() {
        return this.indexm.totalInstitution();
    }

    @Override // com.tdqy.cadre.modular.profess.service.IndexCountService
    public List<Chart> totalCadre(String roleId, String unitCode) {
        return this.indexm.totalCadreSummary(roleId, unitCode);
    }

    @Override // com.tdqy.cadre.modular.profess.service.IndexCountService
    public List<Chart> totalCadreUser(String userId, String unitCode) {
        return this.indexm.totalCadreSummaryUser(userId, unitCode);
    }

    @Override // com.tdqy.cadre.modular.profess.service.IndexCountService
    public List<Chart> totalEducation(String roleId, String unitCode) {
        return this.indexm.totalEducationSummary(roleId, unitCode);
    }

    @Override // com.tdqy.cadre.modular.profess.service.IndexCountService
    public List<Chart> totalInstitution(String roleId, String unitCode) {
        return this.indexm.totalInstitutionSummary(roleId, unitCode);
    }

    @Override // com.tdqy.cadre.modular.profess.service.IndexCountService
    public List<Chart> totalEducationUser(String userId, String unitCode) {
        return this.indexm.totalEducationSummaryUser(userId, unitCode);
    }

    @Override // com.tdqy.cadre.modular.profess.service.IndexCountService
    public List<Chart> totalInstitutionUser(String userId, String unitCode) {
        return this.indexm.totalInstitutionSummaryUser(userId, unitCode);
    }

    @Override // com.tdqy.cadre.modular.profess.service.IndexCountService
    public List<Chart> totalWarningReport(String userId, String unitCode) {
        return this.chartMapper.getWarningReport(userId, unitCode);
    }

    @Override // com.tdqy.cadre.modular.profess.service.IndexCountService
    public List<Chart> totalWarningReportByStringBuffer(String userId, String unitCode, String sql) {
        List<String> uList = new ArrayList();
        if (unitCode != null) {
            uList = Arrays.asList(unitCode.split(","));
        }
        List<SysConfigEntity> list = this.sysConfigService.queryRangeConfigs();
        String FANWEI_ZHIJI = null;
        String FANWEI_GANBULEIXING = null;
        List<String> lxList = new ArrayList<>();
        try {
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getParamKey().equals("FANWEI_ZHIJI")) {
                    FANWEI_ZHIJI = list.get(i).getParamValue();
                }
                if (list.get(i).getParamKey().equals("FANWEI_GANBULEIXING")) {
                    FANWEI_GANBULEIXING = list.get(i).getParamValue();
                }
            }
            FANWEI_ZHIJI = FANWEI_ZHIJI.replace(",", "','");
            FANWEI_ZHIJI = "'" + FANWEI_ZHIJI + "'";
            lxList = Arrays.asList(FANWEI_GANBULEIXING.split(","));
        } catch (Exception e) {
        }

        Map<String, Object> fmap = new HashMap<>();
        fmap.put("FANWEI_ZHIJI", FANWEI_ZHIJI);
        fmap.put("FANWEI_GANBULEIXING", lxList);
        return this.chartMapper.getWarningReportByStringBufferByUnits(userId, uList, sql, fmap);
    }
}
